/*
 * 文 件    名:  OrderhistoryModel.java
 * 创建日期:  2012-12-16上午11:45:31
 * 版          权:  Epro Technologies Co., Ltd. Copyright 2011-2012,  All rights reserved
 * 作          者:  xrj66010
 */
package com.weipu.common.facade.model;

import org.json.JSONException;
import org.json.JSONObject;

import com.weipu.common.constants.ServerConstant;
import com.weipu.common.constants.ServerConstant.Order;

/** 
 * @Description 订单历史记录模型
 * @version [版本号, 2012-12-16]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 * 
 * @author xrj66010
 */
public class OrderhistoryModel
{
    private String ChangeBy;
    
    private String ChangeOn;
    
    private String Notes;
    
    private String OrderStatusStringFormat;
    
    private String StatusCode;
    
    private String StatusType;
    
    public String getChangeBy()
    {
        return ChangeBy;
    }
    
    public void setChangeBy(String changeBy)
    {
        ChangeBy = changeBy;
    }
    
    public String getChangeOn()
    {
        return ChangeOn;
    }
    
    public void setChangeOn(String changeOn)
    {
        ChangeOn = changeOn;
    }
    
    public String getNotes()
    {
        return Notes;
    }
    
    public void setNotes(String notes)
    {
        Notes = notes;
    }
    
    public String getOrderStatusStringFormat()
    {
        return OrderStatusStringFormat;
    }
    
    public void setOrderStatusStringFormat(String orderStatusStringFormat)
    {
        OrderStatusStringFormat = orderStatusStringFormat;
    }
    
    public String getStatusCode()
    {
        return StatusCode;
    }
    
    public void setStatusCode(String statusCode)
    {
        StatusCode = statusCode;
    }
    
    public String getStatusType()
    {
        return StatusType;
    }
    
    public void setStatusType(String statusType)
    {
        StatusType = statusType;
    }
    
    @Override
    public String toString()
    {
        return tojson().toString();
    }
    
    /**
      * 对象转JSON
      * @return  [参数说明]
      * @return JSONObject [返回类型说明]
      * @exception throws [违例类型] [违例说明]
      * @see [类、类#方法、类#成员]
      */
    public JSONObject tojson()
    {
        JSONObject json = new JSONObject();
        try
        {
            if (null != ChangeBy)
            {
                json.put(Order.CHANGEBY, ChangeBy);
            }
            
            if (null != ChangeOn)
            {
                json.put(Order.CHANGEON, ChangeOn);
            }
            if (null != OrderStatusStringFormat)
            {
                json.put(Order.ORDERSTATUSSTRINGFORMAT, OrderStatusStringFormat);
            }
            if (null != StatusCode)
            {
                json.put(Order.STATUSCODE, StatusCode);
            }
            if (null != StatusType)
            {
                json.put(Order.STATUSTYPE, StatusType);
            }
            if (null != Notes)
            {
                json.put(Order.NOTES, Notes);
            }
        }
        catch (JSONException e)
        {
            e.printStackTrace();
        }
        return json;
    }
    
    /**
      * JsonArray转化为orderHistoryModel
      * @param json
      * @return  [参数说明]
      * @return OrderhistoryModel [返回类型说明]
      * @exception throws [违例类型] [违例说明]
      * @see [类、类#方法、类#成员]
      */
    public static OrderhistoryModel jsonArray2Order(JSONObject json)
    {
        OrderhistoryModel orderHistoryModel = new OrderhistoryModel();
        if (json.optString(ServerConstant.Order.CHANGEBY) != JSONObject.NULL
            && !json.isNull(ServerConstant.Order.CHANGEBY))
        {
            orderHistoryModel.setChangeBy(json.optString(ServerConstant.Order.CHANGEBY));
        }
        if (json.optString(ServerConstant.Order.CHANGEON) != JSONObject.NULL
            && !json.isNull(ServerConstant.Order.CHANGEON))
        {
            orderHistoryModel.setChangeOn(json.optString(ServerConstant.Order.CHANGEON));
        }
        if (json.optString(ServerConstant.Order.NOTES) != JSONObject.NULL && !json.isNull(ServerConstant.Order.NOTES))
        {
            orderHistoryModel.setNotes(json.optString(ServerConstant.Order.NOTES));
        }
        if (json.optString(ServerConstant.Order.ORDERSTATUSSTRINGFORMAT) != JSONObject.NULL
            && !json.isNull(ServerConstant.Order.ORDERSTATUSSTRINGFORMAT))
        {
            orderHistoryModel.setOrderStatusStringFormat(json.optString(ServerConstant.Order.ORDERSTATUSSTRINGFORMAT));
        }
        if (json.optString(ServerConstant.Order.STATUSCODE) != JSONObject.NULL
            && !json.isNull(ServerConstant.Order.STATUSCODE))
        {
            orderHistoryModel.setStatusCode(json.optString(ServerConstant.Order.STATUSCODE));
        }
        if (json.optString(ServerConstant.Order.STATUSTYPE) != JSONObject.NULL
            && !json.isNull(ServerConstant.Order.STATUSTYPE))
        {
            orderHistoryModel.setStatusType(json.optString(ServerConstant.Order.STATUSTYPE));
        }
        return orderHistoryModel;
    }
    
    /** json 转 收藏实体
     * @param jsonString 错误的json格式将返回一个null
     * @return [参数说明]
     * @return UserModel [返回类型说明]
     * @exception throws [违例类型] [违例说明]
     * @see [类、类#方法、类#成员]
     */
    public static OrderhistoryModel jsonArray2Order(String jsonString)
    {
        if (null == jsonString || "".equals(jsonString.trim()))
        {
            return null;
        }
        
        OrderhistoryModel model = null;
        try
        {
            JSONObject json = new JSONObject(jsonString);
            model = jsonArray2Order(json);
        }
        catch (JSONException e)
        {
        }
        return model;
    }
    
}
